package xyz.scootaloo.oj.leetcode

import org.junit.Test
import xyz.scootaloo.common.TestDsl
import kotlin.math.max

/**
 * @author flutterdash@qq.com
 * @since 2021/7/4 16:16
 */
class P198 : TestDsl {

    private fun rob(nums: IntArray): Int {
        if (nums.isEmpty())
            return 0
        if (nums.size == 1)
            return nums[0]
        if (nums.size == 2)
            return max(nums[0], nums[1])

        val size = nums.size
        val dp = IntArray(size + 1)
        dp[0] = 0
        dp[1] = nums[0]
        for (i in 2..size) {
            dp[i] = max(nums[i - 1] + dp[i - 2], dp[i - 1])
        }

        return dp[size]
    }

    @Test
    fun test0() {
        rob(intArrayOf(1, 2, 3, 1)) shouldBe 4
        rob(intArrayOf(2, 7, 9, 3, 1)) shouldBe 12
        rob(intArrayOf(2, 1, 1, 2)) shouldBe 4
    }

    @Test
    fun test1() {
        var a = 1
        var b = 2
        "a=$a, b=$b".log()
        b = a.also { a = b }
        "a=$a, b=$b".log()
    }

}
